/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

FIVe3D
Flash Interactive Vector-based 3D
Mathieu Badimon  |  five3d@mathieu-badimon.com

http://five3D.mathieu-badimon.com  |  http://five3d.mathieu-badimon.com/archives/  |  http://code.google.com/p/five3d/

/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import net.badimon.five3D.geom.Matrix;
import net.badimon.five3D.geom.Point;

class net.badimon.five3D.display.Motif {

	public static function clone(motif:Array):Array {
		var motif2:Array = [];
		for (var i:Number = 0;i < motif.length; i++) {
			switch (motif[i][0]) {
				case "B":
					motif2.push(['B', [motif[i][1][0], motif[i][1][1]]]);
					break;
				case "S":
					motif2.push(['S', [motif[i][1][0], motif[i][1][1], motif[i][1][2]]]);
					break;
				case "M":
					motif2.push(['M', [motif[i][1][0], motif[i][1][1]]]);
					break;
				case "L":
					motif2.push(['L', [motif[i][1][0], motif[i][1][1]]]);
					break;
				case "C":
					motif2.push(['C', [motif[i][1][0], motif[i][1][1], motif[i][1][2], motif[i][1][3]]]);
					break;
				case "E":
					motif2.push(['E']);
					break;
			}
		}
		return motif2;
	}

	public static function project(motif:Array, matrix:Matrix, viewdistance:Number):Void {
		for (var i:Number = 0;i < motif.length; i++) {
			switch (motif[i][0]) {
				case "M":
				case "L":
					var pt:Point = matrix.transformPoint(new Point(motif[i][1][0], motif[i][1][1], 0));
					pt.project(pt.getPerspective(viewdistance));
					motif[i][1][0] = pt.x;
					motif[i][1][1] = pt.y;
					break;
				case "C":
					var pt1:Point = matrix.transformPoint(new Point(motif[i][1][0], motif[i][1][1], 0));
					var pt2:Point = matrix.transformPoint(new Point(motif[i][1][2], motif[i][1][3], 0));
					pt1.project(pt1.getPerspective(viewdistance));
					pt2.project(pt2.getPerspective(viewdistance));
					motif[i][1][0] = pt1.x;
					motif[i][1][1] = pt1.y;
					motif[i][1][2] = pt2.x;
					motif[i][1][3] = pt2.y;
					break;
			}
		}
	}

	public static function draw(clip:MovieClip, motif:Array):Void {
		for (var i:Number = 0;i < motif.length; i++) {
			switch (motif[i][0]) {
				case "B":
					clip.beginFill(motif[i][1][0], motif[i][1][1]);
					break;
				case "S":
					clip.lineStyle(motif[i][1][0], motif[i][1][1], motif[i][1][2]);
					break;
				case "M":
					clip.moveTo(motif[i][1][0], motif[i][1][1]);
					break;
				case "L":
					clip.lineTo(motif[i][1][0], motif[i][1][1]);
					break;
				case "C":
					clip.curveTo(motif[i][1][0], motif[i][1][1], motif[i][1][2], motif[i][1][3]);
					break;
				case "E":
					clip.endFill();
					break;
			}
		}
	}
}